/**
 * \file ThreadManager.h
 * \brief ThreadManager definition class
 * \author Edouard ROGE
 * \date 29 august 2012
 */

#ifndef _THREADMANAGER_
#define _THREADMANAGER_


#include <vector>
#include "Core/Define/Define.h"
#include "Core/Pattern/Singleton.h"

namespace Core
{
	namespace Thread
	{
		class Thread;

		/**
		 * \class ThreadManager
		 * \brief class that manages the threads
		 */
		class ThreadManager : public Singleton<ThreadManager>
		{
		public:

			/**
			 * \fn ThreadManager();
			 * \brief Default Constructor
			 */
			ThreadManager();

			/**
			 * \fn virtual ~ThreadManager();
			 * \brief Destructor
			 */
			virtual ~ThreadManager();

			/**
			 * \fn uint32 GetMaxThread() const;
			 * \return the number of the maximum thread
			 * \brief get the number of maximum thread that are able to run simultaneous
			 */
			uint32 GetMaxThread() const;

			/**
			 * \fn uint32 GetRunningThreads() const;
			 * \return the number of running threads
			 * \brief get the number of running threads
			 */
			uint32 GetRunningThreads() const;

			/**
			 * \fn void Register(Thread * _pThread);
			 * \param _pThread task to register into the manager
			 * \brief register a task into the manager
			 */
			void Register(Thread * _pThread);

			/**
			 * \fn void Unregister(Thread * _pThread);
			 * \param _pThread task to unregister
			 * \brief unregister a task from the manager
			 */
			void Unregister(Thread * _pThread);

			/**
			 * \fn void Clear();
			 * \brief Wait for all the running thread and unregister them
			 */
			void Clear();

		private:

			/** Max thread number */
			static const uint32 MAX_THREAD = 64;

			/** array of the tasks that are running */
			std::vector<Thread *> m_Threads;

			/** mutex */
			std::mutex m_mutex;
		};
	}
}

#endif /* _THREADMANAGER_ */
